package Year22_Month03.day01;


import java.util.Stack;

public class Main2 {
    public boolean chkParenthesis(String A, int n) {
        // write code here
        Stack box = new Stack();
        if(n % 2 == 1){
            return false;
        }
        char[] arr = A.toCharArray();
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] == '(' || arr[i] == '{' || arr[i] == '['){
                box.push(arr[i]);
            }else if(arr[i] == ')' || arr[i] == '}' || arr[i] == ']'){
                if(!box.empty()) {
                    box.pop();
                }
            }else{
                return false;
            }

        }
        return box.empty();
    }
}
